package ldh.im.fxbase.data.pojo.status;

import ldh.rpc.dto.ValueEnum;
import ldh.im.dto.enums.MessageRefType;

public enum ImMessageRefType implements ValueEnum<Byte> {
    ref(1, "引用"),
    transfer(2, "转发"),
    ;

    private Byte value;
    private String desc;

    private ImMessageRefType(Integer value, String desc){
        this.value = value.byteValue();
        this.desc = desc;
    }

    @Override
    public Byte getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }

    public static ImMessageRefType getByValue(Integer value) {
        if (value == null) return null;
        for (ImMessageRefType groupType : ImMessageRefType.values()) {
            if (groupType.getValue() == value.byteValue()) {
                return groupType;
            }
        }

        throw new RuntimeException("ImMessageRefType不支持这个值：" + value);
    }

    public MessageRefType toMessageRefType() {
        if (this == ref) {
            return MessageRefType.ref;
        } else if (this == transfer) {
            return MessageRefType.transfer;
        }
        throw new RuntimeException("ImMessageRefType不支持这个值：" + getDesc());
    }

    public static ImMessageRefType wrap(MessageRefType refType) {
        if (refType == null) return null;
        if (refType == MessageRefType.ref) {
            return ref;
        } else if (refType == MessageRefType.transfer) {
            return transfer;
        }
        throw new RuntimeException("ImMessageRefType不支持这个值：" + refType.name());
    }
}
